#ifndef _MY_STRING_H_
#define _MY_STRING_H_

#include "Object.h"

namespace MySTL
{

class String : public Object
{
public:
	String();
	String(const char* str);
	String(char c);
	String(const String& obj);
	~String();

	String& operator =(const char* str);
	String& operator =(char c);
	String& operator =(const String& obj);

	char& operator [](int n);
	const char& operator [](int n) const;

	bool startWith(const char* str) const;
	bool startWith(const String& obj) const;
	bool endOf(const char* str) const;
	bool endOf(const String& obj) const;
	int length() const;
	const char* c_str() const;
	String& trim();
	String& insert(int n, const char* str);
	String& insert(int n, const String& obj);
	String& remove(int n, int len);
	String& remove(const char* str);
	String& remove(const String& obj);
	String& replace(int n, int len, const char* str);
	String& replace(int n, int len, const String& str);
	String& replace(const char* before, const char* after);
	String& replace(const String& before, const char* after);
	String& replace(const char* before, const String& after);
	String& replace(const String& before, const String& after);

	int indexOf(const char* str, int from = 0) const;
	int indexOf(const String& str, int from = 0) const;

	bool operator ==(const char* str) const;
	bool operator ==(const String& obj) const;
	bool operator !=(const char* str) const;
	bool operator !=(const String& obj) const;
	bool operator <(const char* str) const;
	bool operator <(const String& obj) const;
	bool operator <=(const char* str) const;
	bool operator <=(const String& obj) const;
	bool operator >(const char* str) const;
	bool operator >(const String& obj) const;
	bool operator >=(const char* str) const;
	bool operator >=(const String& obj) const;

protected:
	void init(const char* str);
	void update(const char* str);
	bool equal(const char* str, int from, int to) const;
	int* get_pmt(const char* str, int len) const;
	int kmp(const char* str, int from = 0) const;

protected:
	char* m_str;
	int m_length;
};

}

#endif